package com.xplusplus.security.controller;

import com.xplusplus.security.domain.Result;
import com.xplusplus.security.service.ImportUserMessageService;
import com.xplusplus.security.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author: zhouweixin
 * @Description: 导入用户的信息
 * @Date: Created in 21:12 2018/10/24
 * @Modified By:
 */
@RestController
@RequestMapping(value = "/importUserMessage")
@Api(tags = "导入用户的信息")
public class ImportUserMessageController {

    @Autowired
    private ImportUserMessageService importUserMessageService;

    @ApiOperation(value = "查询所有的导入信息")
    @GetMapping(value = "/getAll")
    public Result<Object> getAll(){
        return ResultUtil.success(importUserMessageService.getAll());
    }

    @GetMapping(value = "/getLastest")
    @ApiOperation(value = "查询最新的导入信息")
    public Result<Object> getLastest(){
        return ResultUtil.success(importUserMessageService.getLastest());
    }

    @GetMapping(value = "/getLastestByStatus")
    @ApiOperation(value = "通过状态查询最新的导入信息")
    public Result<Object> getLastestByStatus(@ApiParam(value = "status", defaultValue = "失败") @RequestParam(defaultValue = "失败") String status){
        return ResultUtil.success(importUserMessageService.getLastestByStatus(status));
    }

    @GetMapping(value = "/getByTime")
    @ApiOperation(value = "通过时间查询导入信息")
    public Result<Object> getByTime(@ApiParam(value = "time") @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date time){
        return ResultUtil.success(importUserMessageService.getByTime(time));
    }

    @GetMapping(value = "/getByStatusAndTime")
    @ApiOperation(value = "通过状态和时间查询")
    public Result<Object> getByStatusAndTime(@ApiParam(value = "status", defaultValue = "失败") @RequestParam(defaultValue = "失败") String status,
                                             @ApiParam(value = "time") @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date time){
        return ResultUtil.success(importUserMessageService.getByStatusAndTime(status, time));
    }

    @GetMapping(value = "/deleteById")
    @ApiOperation(value = "通过主键删除")
    public Result<Object> deleteById(@ApiParam(value = "id") @RequestParam Long id){
        importUserMessageService.deleteById(id);
        return ResultUtil.success();
    }

    @GetMapping(value = "/deleteAll")
    @ApiOperation(value = "删除所有")
    public Result<Object> deleteAll(){
        importUserMessageService.deleteAll();
        return ResultUtil.success();
    }

    @GetMapping(value = "/deleteByIds")
    @ApiOperation(value = "批量删除")
    public Result<Object> deleteByIds(@ApiParam(value = "id") @RequestParam Long[] ids){
        importUserMessageService.deleteByIds(ids);
        return ResultUtil.success();
    }
}
